package com.chis.jxc;

import com.chis.jm.bean.jxc.CntstmInfoBean;
import com.chis.jmdatatimer.comm.TxMgmtModule;
import com.chis.util.RandomGUID;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

public class GenStmcode extends Thread{
    public String guid;
    public String stmguid;
    public String eleccode;
    public String midcode;
    public String bigcode;
    public String forcode;
    public Integer codetype;
    public Integer balance;
    public static TxMgmtModule txMgmtModule;


    public static void main(String[] args) {

        ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"spring.xml"});
        context.start();
        txMgmtModule = (TxMgmtModule) context.getBean("TxMgmtModule");

        try {
            for(int i = 1 ; i <= 10 ; i++){
                GenStmcode genStmcode = new GenStmcode();
                genStmcode.start();
            }

        } catch (Exception e){
            e.printStackTrace();
        }

        
    }

    @Override
    public void run() {
//        inserttest();
        findtest();

    }

    public void findtest(){

        for(int i = 0 ; i< 10 ; i++){
            long l1 =  System.currentTimeMillis();
            List<String> list = txMgmtModule.findElec("968D899C-3C59-A855-6886-b580B0310901");
            System.out.println("数量："+list.size()+"  耗时："+(System.currentTimeMillis()-l1));
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }

    }


    public void inserttest(){
        List<String> list = txMgmtModule.findkcguid();
        System.out.println(list.size());
        List<GenStmcode> list1 = new ArrayList<>();
        Integer cunkl = 0;
        for(String s : list){
            list1 = new ArrayList<>();
            for(int i = 0 ; i < 200 ; i++){
                GenStmcode genStmcode = new GenStmcode();
                genStmcode.setStmguid(s);
                String codenum = gennum();
                genStmcode.setEleccode(codenum);
                genStmcode.setMidcode(codenum);
                genStmcode.setBigcode(codenum);
                genStmcode.setForcode(codenum);
                genStmcode.setCodetype(1);
                genStmcode.setBalance(2);
                list1.add(genStmcode);

            }
            long l1 =  System.currentTimeMillis();
            txMgmtModule.addkcguid(list1);
            System.out.println("插入数量："+(cunkl+=200)+" 耗时："+(System.currentTimeMillis()-l1));
            if(cunkl > 1000000){
                break;
            }
        }
    }


    public static String gennum(){

        String s1 = String.valueOf((int)(Math.random() * 1000000000));
        String s2 = String.valueOf((int)(Math.random() * 1000000000));
        return s1+s2;
    }


    public String getGuid() {
        return guid;
    }

    public void setGuid(String guid) {
        this.guid = guid;
    }

    public String getStmguid() {
        return stmguid;
    }

    public void setStmguid(String stmguid) {
        this.stmguid = stmguid;
    }

    public String getEleccode() {
        return eleccode;
    }

    public void setEleccode(String eleccode) {
        this.eleccode = eleccode;
    }

    public String getMidcode() {
        return midcode;
    }

    public void setMidcode(String midcode) {
        this.midcode = midcode;
    }

    public String getBigcode() {
        return bigcode;
    }

    public void setBigcode(String bigcode) {
        this.bigcode = bigcode;
    }

    public String getForcode() {
        return forcode;
    }

    public void setForcode(String forcode) {
        this.forcode = forcode;
    }

    public Integer getCodetype() {
        return codetype;
    }

    public void setCodetype(Integer codetype) {
        this.codetype = codetype;
    }

    public Integer getBalance() {
        return balance;
    }

    public void setBalance(Integer balance) {
        this.balance = balance;
    }
}
